import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'finaFlockingM', //理财直融指令
  state: {
    agencyList: [],
  },
  effects: {
    //指令下达新增
    *orderSave({ payload, callback }, { call, put }) {
      const response = yield call(api.finaFlocking.orderSave, payload);
      callback(response);
    },
    //簿记新增 修改
    *tradeBookSave({ payload, callback }, { call, put }) {
      const response = yield call(api.finaFlocking.tradeBookSave, payload);
      callback(response);
    },
    //交易录入
    *tradeAdd({ payload, callback }, { call, put }) {
      const response = yield call(api.finaFlocking.tradeAdd, payload);
      callback(response);
    },
    //获取行为事件数据
    *queryEventByCode({ payload, callback }, { call, put }) {
      const response = yield call(api.finaFlocking.queryEventByCode, payload);
      if (response && response.code == 0) {
        callback(response);
      } else {
        message.error(response ? response.msg : '获取行为事件信息失败!');
      }
    },
    //查询基础信息
    *queryBaseInfo({ payload, callback }, { call, put }) {
      const response = yield call(api.finaFlocking.queryBaseInfo, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        message.error(response ? response.msg : '查询理财直融基础信息失败!');
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
